const obj = {
  name: 'puck',
  age: 12
}

function objNameFn1() {
  console.log('name changed, objNameFn1 run')
}

function objNameFn2() {
  console.log('name changed, objNameFn2 run')
}

function objAgeFn() {
  console.log('age changed')
}

/**
 * 寻找数据结构来保存映射关系
 * obj---Fn
 * name---nameFn
 * age---ageFn
 */
const objMap = new Map()
objMap.set('name', [objNameFn1, objNameFn2])
objMap.set('age', objAgeFn)
const objWeakMap = new WeakMap()
objWeakMap.set(obj, objMap)

/**
 * 当name发生改变时调用objNameFn
 */
obj.name = 'lucy'
//1.根据obj获取objMap
const newObjMap = objWeakMap.get(obj)
const arr = newObjMap.get('name')
arr.forEach(item => item())
//name changed, objNameFn1 run
// name changed, objNameFn2 run
